﻿import com.dmotiko.general.*
import com.dmotiko.chabeli.*
import com.dmotiko.util.*
import mx.transitions.easing.None;
import mx.transitions.easing.Regular;
import mx.transitions.Tween;

class ChabeliProductLoader
extends MovieLoaderClip {
	
	private var mcShadow:MovieClip;
	private var mcStroke:MovieClip;
	private var bVisited:Boolean;
	private var bActive:Boolean;
			
	private function ChabeliProductLoader() {
		super();
	}
	
	private function initClip():Void {
		super.initClip();
		mcShadow._alpha = 0;
		mcStroke._alpha = 0;
	}
	
	private function refreshData() {
		var photo:ChabeliProductData = ChabeliProductData( data );
		this.loadContent( photo.getIcon() );
	}
	
	public function onRollOver() {
		this.registerTween( "strokeTween", new Tween( mcStroke, "_alpha", Regular.easeOut, mcStroke._alpha, 100, 0.5, true ) );
	}
	
	public function onRollOut() {
		if ( bActive ) return;
		this.registerTween( "strokeTween", new Tween( mcStroke, "_alpha", Regular.easeOut, mcStroke._alpha, 0, 0.5, true ) );
	}
	
	public function onRelease() {
		if ( !bVisited ) {
			bVisited = true;
			registerTween("shadowTween", new Tween( mcShadow, "_alpha", Regular.easeOut, mcShadow._alpha, 40, 0.5, true) );
		}
		dispatchEvent( { target: this, type: BaseClipEvent.CHANGED } );
	}
	
	public function setActive(b):Void {
		bActive = b;
		if ( !b ) onRollOut();
	}
		
	public function onLoadInit(target) {
		if (mcContainer.getDepth() > mcShadow.getDepth()) mcContainer.swapDepths(mcShadow);
		this.mcContainer._alpha = 0;
		this.registerTween( "containerTween", new Tween( mcContainer, "_alpha", Regular.easeOut, mcContainer._alpha, 100, 0.5, true ) );
		super.onLoadInit();
	}
		
}